{% extends 'base.html' %}
{% load form_filters %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h2>{{ submission.template.title }}</h2>
            <p class="text-muted">
                提交人：{{ submission.submitted_by.username }} | 
                提交时间：{{ submission.submitted_at|date:"Y-m-d H:i" }}
            </p>
        </div>
        <div>
            <a href="{% url 'submission_list' submission.template.id %}" class="btn btn-outline-secondary">
                返回列表
            </a>
        </div>
    </div>

    {% regroup submission.template.formfield_set.all by section_order as section_list %}
    {% for section in section_list %}
        <div class="card mb-4">
            <div class="card-header bg-primary text-white">
                <h4 class="mb-0">第 {{ section.grouper }} 组</h4>
            </div>
            <div class="card-body">
                {% for field in section.list %}
                    <div class="mb-3">
                        <label class="form-label">{{ field.label }}</label>
                        <div>
                            {% with field_value=submission.data|get_field_value:field.id %}
                                {% if field.field_type == 'image' %}
                                    {% if field_value %}
                                        {% for image_path in field_value %}
                                            <img src="{{ MEDIA_URL }}{{ image_path }}" 
                                                 class="img-thumbnail me-2 mb-2" 
                                                 style="max-height: 200px;">
                                        {% endfor %}
                                    {% else %}
                                        <span class="text-muted">未上传图片</span>
                                    {% endif %}
                                {% elif field.field_type == 'checkbox' %}
                                    {% if field_value %}
                                        {% for value in field_value %}
                                            <span class="badge bg-secondary me-2">{{ value }}</span>
                                        {% endfor %}
                                    {% else %}
                                        <span class="text-muted">未选择</span>
                                    {% endif %}
                                {% else %}
                                    {{ field_value|default:"未填写" }}
                                {% endif %}
                            {% endwith %}
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>
    {% endfor %}
</div>
{% endblock %} 